#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;

class Solution
{
public:
    int subarraysDivByK(vector<int>& nums, int k)
    {
        unordered_map<int, int> hash;
        hash[0] = 1;
        int sum = 0, ret = 0;
        for (auto x : nums)
        {
            sum += x;
            int remainder = (sum % k + k) % k;
            if (hash.count(remainder)) ret += hash[remainder];
            hash[remainder]++;
        }
        return ret;
    }
};

int main()
{
    vector<int> nums;
    Solution sol;
    nums.push_back(4);
    nums.push_back(5);
    nums.push_back(0);
    nums.push_back(-2);
    nums.push_back(-3);
    nums.push_back(1);

    int ret = sol.subarraysDivByK(nums, 5);

    cout << ret << endl;
    return 0;
}